import request from '@/utils/request'

// 获取客户列表
export function getCustomerList(params) {
  return request({
    url: '/api/customers',
    method: 'get',
    params
  })
}

// 根据ID获取客户详情
export function getCustomerById(id) {
  return request({
    url: `/api/customers/${id}`,
    method: 'get'
  })
}

// 新增客户
export function createCustomer(data) {
  return request({
    url: '/api/customers',
    method: 'post',
    data
  })
}

// 更新客户信息
export function updateCustomer(id, data) {
  return request({
    url: `/api/customers/${id}`,
    method: 'put',
    data
  })
}

// 删除客户
export function deleteCustomer(id) {
  return request({
    url: `/api/customers/${id}`,
    method: 'delete'
  })
}

// 批量删除客户
export function batchDeleteCustomers(ids) {
  return request({
    url: '/api/customers/batch',
    method: 'delete',
    data: { ids }
  })
}

// 导出客户Excel
export function exportCustomers(params) {
  return request({
    url: '/api/customers/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 获取业务经理选项
export function getManagerOptions() {
  return request({
    url: '/api/employees/managers',
    method: 'get'
  })
}

/**
 * 检查客户代码唯一性
 * @param {string} customerCode 客户代码
 * @param {string} excludeId 排除的ID（编辑时使用）
 */
export function checkCustomerCodeUnique(customerCode, excludeId = null) {
  return request({
    url: '/api/customers/check-code',
    method: 'get',
    params: {
      customerCode,
      excludeId
    }
  })
} 